package com.xk857.simpleeffect.activity;

import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.xk857.simpleeffect.R;
import com.xk857.simpleeffect.db.PersonDataBase;
import com.xuexiang.xui.widget.actionbar.TitleBar;
import com.xuexiang.xui.widget.button.switchbutton.SwitchButton;

public class SettingActivity extends AppCompatActivity {

    private TitleBar titleBar;
    private SwitchButton sbPlay;
    private SwitchButton sbVibrate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.white));
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        setContentView(R.layout.activity_setting);
        initView();
    }

    private void initView() {
        titleBar = findViewById(R.id.title_bar);
        titleBar.setLeftClickListener(v-> finish());
        sbPlay = findViewById(R.id.sb_play);
        sbVibrate = findViewById(R.id.sb_vibrate);

        sbPlay.setOnCheckedChangeListener((buttonView, isChecked) -> PersonDataBase.setPlay(this,isChecked));
        sbVibrate.setOnCheckedChangeListener((buttonView, isChecked) -> PersonDataBase.setVibrate(this,isChecked));

        sbPlay.setChecked(PersonDataBase.isPlay(this));
        sbVibrate.setChecked(PersonDataBase.isVibrate(this));
    }
}